package com.yuyue.note02.controller;

import com.yuyue.note02.error.BusinessException;
import com.yuyue.note02.error.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @RestControllerAdvice 用于标识当前类为REST风格对应的异常处理器
 */
@RestControllerAdvice
public class ProjectExceptionAdvice {
    //拦截的异常类型
    @ExceptionHandler(Exception.class)
    public String doException(Exception e){
        return e.getMessage();
    }

    //拦截业务异常
    @ExceptionHandler(BusinessException.class)
    public String doBusinessException(BusinessException e){
        return e.getErrorCod() + " : " + e.getMessage();
    }

    //拦截系统异常
    @ExceptionHandler(SystemException.class)
    public String doSystemException(SystemException e){
        return e.getMessage();
    }
}
